package com.java.design;

/**
 * 工厂模式
 * 
 * @author Administrator
 *
 */
//某类操作接口
interface Sender {
	public void Send();
}

//实现接口
class MailSender implements Sender {
	public void Send() {
		System.out.println("MailSender实现类");
	}
}

//实现接口
class SmsSender implements Sender {
	public void Send() {
		System.out.println("SmsSender实现类");
	}
}

//服务接口:声明一大堆方法，每一个方法返回一种接口
interface ServiceFactory {
	public Sender sender();
}

//工厂1实现服务接口
class SendMailFactory implements ServiceFactory {
	public Sender sender() {
		return new MailSender();
	}
}

//工厂2实现服务接口
class SendSmsFactory implements ServiceFactory {
	public Sender sender() {
		return new SmsSender();
	}
}

//测试类
public class FactoryMode {
	public static void main(String[] args) {
		// mail工厂
		ServiceFactory serviceFactory = new SendMailFactory();
		serviceFactory.sender().Send();

		// sms工厂
		serviceFactory = new SendSmsFactory();
		serviceFactory.sender().Send();
	}
}
